package org.brisling.oabs.queryService;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.servlet.http.HttpServletResponse;

import org.brisling.authorize.shiro.ShiroSecurityService;
import org.brisling.base.domain.DataTableListDomain;
import org.brisling.base.domain.ListDomain;
import org.brisling.common.ConstSysParam;
import org.brisling.common.exception.DangerousOperatorException;
import org.brisling.oa.domain.OACarApply;
import org.brisling.oabs.queryService.base.QueryBaseOAService;
import org.brisling.sysman.queryService.QueryDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * 
 * <p>Title: QueryCarApplyService</p>
 * <p>Description: bootstrap datatable 用车申请服务类</p>
 * <p>Company: tongking</p>
 * @author jackson wang
 * @since 1.0
 * @version 1.0
 * @date 2016年9月16日 上午12:31:45
 */
@RestController
@RequestMapping("/bsCarApply/query")
public class QueryBSCarApplyService extends QueryBaseOAService<OACarApply>{
	
	
	
	@Autowired
	private	ShiroSecurityService shiroSecurityService;
	@Autowired
	private QueryDictionaryService dicService;
	
	
	public QueryBSCarApplyService(){
		this.moduleName = ConstSysParam.MODULE_OA_CAR_APPLY;
		this.subSystem = ConstSysParam.SUBSYSTEM_OA;
		this.tableName = ConstSysParam.VIEW_PREFIX +this.moduleName;
		this.clazz = OACarApply.class;
		
		typeMap = this.getTypeMap(clazz);
		
		orderMap.put("bizno",null);
		
		
	}
	
	@PersistenceContext(unitName=ConstSysParam.SUBSYSTEM_SYSMAN)
	@Autowired
	protected void setEntityManager(EntityManager entityManager){
		this.entityManager = entityManager;		
	}
	
	/**
	 * 获取指定名称的视图层对象（html）
	 * @param code
	 * @return
	 */
	@RequestMapping("/getPage.action")
	public ModelAndView getPage(@RequestParam(value="code",required=false) String code){
		String _code = code==null?"main":code;
		return new ModelAndView(String.format("/%1$s/%2$s/%3$s",this.subSystem, this.moduleName,_code));
	}
	@RequestMapping("/mainPage.action")
	public ModelAndView getMainPage(){
		return this.getBizMainPage();
	}
	
	
	/* (non-Javadoc)
	 * @see org.brisling.service.sysman.DepartmentServiceInf#getEditPage()
	 */
	@RequestMapping("/editPage.action")
	public ModelAndView getEditPage(){
		return this.getBizEditPage();
	}
		
	
	@RequestMapping("/getListDomain.action")
	public DataTableListDomain<OACarApply> getBizListDomain(
			@RequestBody(required=false) String body){		
		
		return super.getBizListDomain(body);
	}
	
	@RequestMapping("/getOperateTaskListDomain.action")
	public DataTableListDomain<OACarApply> getOperateTask(@RequestBody(required=false) String body){
				
		return super.getOperateTask(body);
	}
	
	@RequestMapping("/getSignedTaskListDomain.action")
	public DataTableListDomain<OACarApply> getUserSignedTask(@RequestBody(required=false) String body){
		return super.getUserSignedTask(body);
	}
	
	@RequestMapping("/getUnsignedTaskListDomain.action")
	public DataTableListDomain<OACarApply> getUserUnsignedTask(@RequestBody(required=false) String body){
		
		return super.getUserUnsignedTask(body);
	}
	
	
	@RequestMapping("/getFinishedTaskListDomain.action")
	public DataTableListDomain<OACarApply> getUserFinishedTask(@RequestBody(required=false) String body){
		
			
		return super.getUserFinishedTask(body);
	}
	
	
	@RequestMapping("/getAllTaskListDomain.action")
	public DataTableListDomain<OACarApply> getAllTask(@RequestBody(required=false) String body){
					
		return super.getAllTask(body);
	}
	
	@RequestMapping("/getUserManagedTaskDomain.action")
	public DataTableListDomain<OACarApply> getUserManagedTask(@RequestBody(required=false) String body){
		
		return super.getUserManagedTask(body);
	}
	
	@RequestMapping("/exportExcel.action")
	public void exportExcel(@RequestBody(required=false) String body,HttpServletResponse response){
		
		String sqlid= "medical_inquiry_export";
		String title = "医疗服务质询";
		super.exportExcel(body, sqlid, title, response);
	}
	
	
	@RequestMapping("/getTaskListDomain.action")
	public DataTableListDomain<OACarApply> getTaskListDomain(@RequestBody(required=false) String body){
		
		
		return super.getTaskListDomain(body);
	}
	
	
	
	
	/**
	 * 根据用户id查找用户信息
	 * @param id	用户id
	 * @return 用户信息记录 
	 */
	@RequestMapping("/getOne.action")
	public OACarApply getOne(@RequestParam(value="id",required=false) Long id){
		return super.getOne(id);
	}
	
	/**
	 * 根据用户唯一编码查找用户信息
	 * @param identify	用户唯一编码
	 * @return 用户信息记录
	 */
	@RequestMapping("/getOneByIdentify.action")
	public OACarApply getOneByIdentify(@RequestParam(value="identify",required=false) String identify){	
		return super.getOneByIdentify(identify);
	}
	
	/**
	 * 根据用户唯一编码查找用户信息
	 * @param identify	用户唯一编码
	 * @return 用户信息记录
	 */
	@RequestMapping("/getOneByField.action")
	public OACarApply getOneByField(@RequestParam(value="field",required=false) String field,
			@RequestParam(value="fieldVal",required=false) String fieldVal){	
		return super.getOneByIdentify(field,fieldVal);
	}
	
	
	
	/**
	 * 返回流程记录流程实例的执行记录
	 * @param body	包含procInstId在内的参数信息
	 * @return
	 */
	
	@RequestMapping("/flowHistoricsListDomain.action")
	public ListDomain<Object> getHistoricByProcInstId(@RequestBody(required=false) String body){
		
		String sql = dicService.getSqlByBizcode("flow_historics");				
		return super.getHistoricByProcInstId(body, sql);
	}
	
	public String generateBizno(){
		return super.generateBizno();
	}
	/**
	 * 查询窗口满意度异常数据
	 * @return
	 *
	 */	
	
	public List<OACarApply> getWindowUnSatisfy(){		
		
		String sql =dicService.getSqlByBizcode("duties_abnormal_OACarApply");		
		
		try {
			return super.getClassedAllList(sql, OACarApply.class);
		} catch (DangerousOperatorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 	
		return null;
	}

}
